
enum SIZE {
    //% block="29*29"
    1,
    //% block="58*58"
    2
}

enum LINE {
    //% block="1"
    1,
    //% block="2"
    2,
    //% block="3"
    3,
    //% block="4"
    4
}

enum BTN {
    //% block="A"
    A,
    //% block="B"
    B,
    //% block="A+B"
    AB
}


//% color="#7DDA58" iconWidth=50 iconHeight=40
namespace maqueen1114 {
    // //% block="PID操作" blockType="tag"
    // export function tagPID() {}
    
    //% block="设置PID参数 P[P] I[I] D[D]" blockType="command"
    //% P.shadow="number" P.defl="7"
    //% I.shadow="number" I.defl="7"
    //% D.shadow="number" D.defl="7"
    export function setTunings(parameter: any, block: any) {
        let p = parameter.P.code;
        let i = parameter.I.code;
        let d = parameter.D.code;
        Generator.addInclude("maqueen1114","#include <maqueen.h>",true);
        Generator.addCode(`setTunings(${p},${i},${d});`);
    }

    //% block="PID计算 偏差：[ERR]" blockType="reporter"
    //% ERR.shadow="number" ERR.defl="7"
    export function compute(parameter: any, block: any) {
        let err = parameter.ERR.code;
        Generator.addInclude("maqueen1114","#include <maqueen.h>",true);
        Generator.addCode(`compute(${err})`);
    }

    // //% block="传感器操作" blockType="tag"
    // export function tagtest() {}

    //% block="巡线传感器数据转换 L2[LL] L1[L] R1[R] R2[RR]" blockType="reporter"
    //% LL.shadow="normal"
    //% L.shadow="normal"
    //% R.shadow="normal"
    //% RR.shadow="normal"
    export function transfer(parameter: any, block: any){
        let ll = parameter.LL.code;
        let l = parameter.L.code;
        let r = parameter.R.code;
        let rr = parameter.RR.code;
        Generator.addInclude("maqueen1114","#include <maqueen.h>",true);
        Generator.addCode(`transfer(${ll},${l},${r},${rr})`);

    }

    //% block="获取巡线偏差 巡线传感器数据[SS] 比例 [CA]" blockType="reporter"
    //% SS.shadow="normal"
    //% CA.shadow="number"
    export function getGrayError(parameter: any, block: any){
        let ss = parameter.SS.code;
        let ca = parameter.CA.code;
        Generator.addInclude("maqueen1114","#include <maqueen.h>",true);
        Generator.addCode(`getGrayError(${ss}, ${ca})`);
    }

    //% block="获取偏差 传感器值[SEN] 设定值[SET] 比例[SCA]" blockType="reporter"
    //% SEN.shadow="number" SEN.defl="777"
    //% SET.shadow="number" SET.defl="10"
    //% SCA.shadow="range" SCA.params.min=0 SCA.params.max=5 SCA.defl=1
    export function getError(parameter: any, block: any) {
        let sen = parameter.SEN.code;
        let set = parameter.SET.code;
        let sca = parameter.SCA.code;
        Generator.addInclude("maqueen1114","#include <maqueen.h>",true);
        Generator.addCode(`getError(${sen},${set},${sca})`);
    }

}
